package org.hot100_0.leetcode21;

import org.leetcode.easy.ListNode;

import java.util.List;

public class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

        ListNode dummy = new ListNode(-1);
        ListNode list= dummy;

        while (list1!=null && list2!=null){
            if (list1.val<list2.val){
                list.next=list1;
                list1=list1.next;
            }else {
                list.next=list2;
                list2=list2.next;
            }
            list=list.next;
        }

        if (list1==null){
            list.next=list2;
        }

        if (list2==null){
            list.next=list1;
        }

        return dummy.next;
    }
}
